home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
TCL1
/
CSPINNER
/
CSPINNER.C
< prev
next >
Wrap
Text File
|
1990-12-20
|
4KB
|
144 lines
/*
CSpinner.c
Implements a spinning cursor. A list of cursors is specified with an
'acur' resource. Repeatedly invoking the Spin() method sequences
through the list of cursors.
SUPERCLASS = CObject.c
Copyright ⌐ 1990 Ursa Major Software. All rights reserved.
*/
#include "CSpinner.h"
typedef struct acurCURS { /* For each cursor in an 'acur' */
short resID; /* CURS resource ID */
short padding; /* Two bytes of padding */
} acurCURS;
typedef struct acurTemplate { /* Resource template for 'acur' */
short numCursors; /* Number of cursors in list */
short counter; /* Counter (not used by us) */
acurCURS CURSlist[]; /* 'CURS' ID/padding pairs */
} acurTemplate, **acurTemplateH;
/*
* Initialize a Spinner object
*/
void CSpinner::ISpinner(
short acurID, /* 'acur' resource ID */
short aThreshold, /* Tick delay before first spin */
short anInterval) /* Ticks between spins */
{
register acurTemplateH tempH; /* 'acur' handle with entries */
/* as ID & padding pairs */
register short i; /* Loop counter */
register CursHandle aCursor; /* Handle to 'CURS' resource */
/* Cursor IDs are in an 'acur' */
/* resource */
tempH = (acurTemplateH) GetResource('acur', acurID);
DetachResource(tempH); /* We are going to change the */
HNoPurge(tempH); /* 'acur' resource in memory. */
/* Treat it as a regular handle */
/* and make it nonpurgeable. */
/* Cursor IDs list entries in the 'acur' are 4 bytes long. */
/* The first 2 bytes are a 'CURS' resource ID and the */
/* last 2 bytes are padding. This is so that the ID/padding */
/* entry can be replaced with a handle (4 bytes long) to */
/* the corresponding 'CURS' resource at runtime. "tempH" */
/* and "acurH" both refer to the same handle. "tempH" */
/* treats the entries as ID/padding pairs, whereas "acurH" */
/* treats the entries as cursor handles. */
acurH = (acurHand) tempH;
for (i = 0; i < (**tempH).numCursors; i++) {
/* Get handle to Cursor */
aCursor = GetCursor((**tempH).CURSlist[i].resID);
HNoPurge(aCursor); /* Make it nonpurgeable */
/* Replace 'CURS' ID/padding pairs */
/* with a handle to the Cursor */
(**acurH).cursors[i] = aCursor;
}
SetTimes(aThreshold, anInterval); /* Specify delay times */
Reset(); /* Initialize counters */
}
/*
* Dispose of a Spinner
*/
void CSpinner::Dispose()
{
DisposHandle(acurH); /* Throw out our modified copy */
/* of the 'acur' resource */
}
/*
* Reset counters to initial values. Subsequent spins will start with
* the first cursor and will occur after the "threshold" delay.
*/
void CSpinner::Reset()
{
cursIndex = 0; /* Start with the first cursor */
nextSpinTime = 0; /* Indicates first spin is next */
}
/*
* Specifiy values for the threshold delay before the first spin
* and the interval between spins
*/
void CSpinner::SetTimes(
short newThreshold,
short newInterval)
{
threshold = newThreshold; /* Set instance variables */
interval = newInterval;
}
/*
* Spin the cursor. Send this message repeatedly during long delays
* to spin the cursor. Cursor spinning is accomplished by changing
* the cursor after a specified time interval.
*/
void CSpinner::Spin()
{
register long theTickCount;
theTickCount = TickCount(); /* Time in ticks since startup */
if (nextSpinTime == 0) { /* Cursor has not yet spun */
/* Set time counter so that the */
/* first spin will occur after */
/* "threshold" ticks */
nextSpinTime = theTickCount + threshold;
} else if (theTickCount >= nextSpinTime) {
/* Enough time has passed. Change */
/* the cursor */
SetCursor(*(**acurH).cursors[cursIndex]);
cursIndex++; /* Increment cursor index */
if (cursIndex >= (**acurH).numCursors) {
cursIndex = 0; /* Wrap around to the first one */
}
/* Next spin will occur after at */
/* least "interval" ticks */
nextSpinTime = theTickCount + interval;
}
}